(function () {
    'use strict';

    angular
        .module('logcenterApp')
        .factory('PropertiesService', PropertiesService);

    PropertiesService.$inject = ['$http', '$q'];

    function PropertiesService($http, $q) {

        var propertiesData = null;

        var service = {
            getProperties: getProperties
        };

        return service;

        function getProperties(isReload) {
            var deferred =$q.defer();
            if(!propertiesData || isReload){
                $http.get('config/config.json').then(function(result) {
                    if (result.data) {
                        var response = {};
                        response.esAddress = result.data.esAddress;
                        response.isMulti = result.data.isMulti;
                        response.kibanaPartition = result.data.kibanaPartition;
                        response.eiinfoAddress = result.data.eiinfoAddress;
                        response.locations = result.data.locations;
                        response.navbarTitle = result.data.navbarTitle;
                        response.logAlertMsgEnabled = result.data.logAlertMsgEnabled;
                        propertiesData =response;
                        deferred.resolve(propertiesData);
                    }
                });
            } else {
                deferred.resolve(propertiesData);
            }

            return deferred.promise;
        }
    }
})();
